package com.wt.struggle.goodbye.sq.adapter

import android.content.Context
import android.graphics.Color
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.ProBaseAdapter
import com.wt.struggle.goodbye.info.FileInfo
import kotlinx.android.synthetic.main.text_layout.view.*

class ColorAdapter(context: Context, list: ArrayList<FileInfo>) : ProBaseAdapter<FileInfo>(context, list) {
    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val vh = holder as VH
        val info = list[position]
        val ss = info.text
        vh.textView.setBackgroundColor(Color.parseColor(ss))
        val w = context.resources.getDimension(R.dimen.dp_20).toInt()
        vh.textView.layoutParams = LinearLayout.LayoutParams(w, w)
        if (info.selector) {
            vh.linearBg.setBackgroundResource(R.drawable.red_kuang_line_4)
        }else{
            vh.linearBg.setBackgroundResource(0)
        }


    }

    override fun onCreateView(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return VH(inflater.inflate(R.layout.text_layout, parent, false))
    }

    override fun onUpdateHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any>) {

    }

    inner class VH(view: View) : RecyclerView.ViewHolder(view) {
        val textView = view.textView
        val linearBg = view.linearBg

    }


    fun update(position: Int) {
        for(i in list.indices){
            val info = list[i]
            info.selector = i==position
        }

       notifyDataSetChanged()
    }
}